package net.searchdata.study;

import java.util.Iterator;
import java.util.List;

public class Entry28Three {
	public <T extends Comparable<T>> T max(List<T> list) {
		Iterator<T> it = list.iterator();
		T result = it.next();

		while (it.hasNext()) {
			T t = it.next();
			result = (result.compareTo(t) > 0) ? result : t;
		}

		return result;
	}

	public static void swap(List<?> list, int i, int j) {
		swapHelper(list, i, j);
	}
	
	private static <E> void swapHelper(List<E> list, int i, int j) {
		list.set(i, list.set(j, list.get(i)));
	}
}